package com.linkhub.oms.admin.modules.stock.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.linkhub.oms.admin.modules.satoken.session.LhSessionContext;
import com.linkhub.oms.admin.modules.stock.domain.param.StockFlowQueryParam;
import com.linkhub.oms.admin.modules.stock.domain.vo.StockFlowVO;
import com.linkhub.oms.admin.modules.stock.domain.vo.StockVO;
import com.linkhub.oms.admin.modules.stock.service.StockFlowBizService;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.enums.mp.RoleCodeEnum;
import com.linkhub.oms.common.response.DataResponse;
import com.linkhub.oms.common.response.PageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName StockFlowController
 * @Description TODO
 * @Author XieYu
 * @Date 2024/6/24 22:42
 * @Version 1.0
 */
@Slf4j
@RestController
@Api(tags = {"库存流水模块"})
@RequestMapping("/stockFlow")
@SaCheckLogin
public class StockFlowController {
    @Resource
    private StockFlowBizService stockFlowBizService;

    @GetMapping("/list/physical")
    @ApiOperation(value = "查询实物库存流水")
    public DataResponse<PageDTO<StockFlowVO>> physicalStocks(@Validated StockFlowQueryParam stockFlowQueryParam) {
        List<String> userRoles = LhSessionContext.getUserRoles();
        stockFlowQueryParam.setCustomerRole(userRoles.contains(RoleCodeEnum.CUSTOMER.getCode()));
        return DataResponse.success(stockFlowBizService.getPhysicalStockFlows(stockFlowQueryParam));
    }

    @GetMapping("/list/preemption")
    @ApiOperation(value = "查询预占库存流水")
    public DataResponse<PageDTO<StockFlowVO>> preemptionStocks(@Validated StockFlowQueryParam stockFlowQueryParam) {
        List<String> userRoles = LhSessionContext.getUserRoles();
        stockFlowQueryParam.setCustomerRole(userRoles.contains(RoleCodeEnum.CUSTOMER.getCode()));
        return DataResponse.success(stockFlowBizService.getPreemptionStockFlows(stockFlowQueryParam));
    }
}
